import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shop/app/modules/productContent/controllers/product_content_controller.dart';
import 'package:shop/tools/screenAdapter.dart';

class CartItemNumView extends GetView {
  @override
  final ProductContentController controller = Get.find();

  CartItemNumView({super.key});

  Widget _left() {
    return InkWell(
      onTap: () {
        controller.decCount();
      },
      child: Container(
        alignment: Alignment.center,
        width: ScreenAdapter.width(80),
        height: ScreenAdapter.height(64),

        child: Text('-'),
      ),
    );
  }

  Widget _center() {
    return Obx(
      () => Container(
        decoration: BoxDecoration(
          border: Border(
            left: BorderSide(
              width: ScreenAdapter.width(2),
              color: Colors.black12,
            ),
            right: BorderSide(
              width: ScreenAdapter.width(2),
              color: Colors.black12,
            ),
          ),
        ),
        alignment: Alignment.center,
        width: ScreenAdapter.width(80),
        height: ScreenAdapter.height(64),

        child: Text("${controller.selectNum.value}"),
      ),
    );
  }

  Widget _right() {
    return InkWell(
      onTap: () {
        controller.incCount();
      },
      child: Container(
        alignment: Alignment.center,
        width: ScreenAdapter.width(80),
        height: ScreenAdapter.height(64),

        child: Text('+'),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenAdapter.width(244),
      height: ScreenAdapter.height(68),
      decoration: BoxDecoration(
        border: Border.all(
          width: ScreenAdapter.width(2),
          color: Colors.black12,
        ),
        borderRadius: BorderRadius.circular(10),
      ),
      child: Row(children: [_left(), _center(), _right()]),
    );
  }
}
